var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("BaseDlgNode"),
    c = t("StarCountCom"),
    p = cc._decorator,
    l = p.ccclass,
    d = p.property,
    u =
        (p.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.starLay = null;
                e.addLab = null;
                e.foodLab = null;
                e.levelLab = null;
                e.redLab = null;
                e.timeLab = null;
                e.upLevelBtn = null;
                e.upLevelNode = null;
                e.zhuanNodeCoin = null;
                e.btnListNode = [];
                e.proLab = null;
                e.btnRendList = [];
                e.isClickNode = !1;
                e.lastTime = 0;
                e.lastId = -1;
                return e;
            }
            e.prototype.onLoad = function () {
                this.upLevelNode.on(cc.Node.EventType.TOUCH_START, this.clickNode.bind(this), this);
                this.upLevelNode.on(cc.Node.EventType.TOUCH_END, this.cancelClick.bind(this), this);
                this.upLevelNode.on(cc.Node.EventType.TOUCH_CANCEL, this.cancelClick.bind(this), this);
                EVUIEffView.on(EVUIEffView.checkCostUI, this.updateView.bind(this), this);
                this.isClickNode = !1;
            };
            e.prototype.clickNode = function () {
                this.upLevelNode.runAction(cc.scaleTo(0.1, 1.2));
                this.upLevel();
                this.isClickNode = !0;
                this.lastTime = Date.now();
            };
            e.prototype.cancelClick = function () {
                this.isClickNode = !1;
                this.upLevelNode.runAction(cc.scaleTo(0.1, 1));
            };
            e.prototype.update = function () {
                if (this.isClickNode && (Date.now() - this.lastTime > 500 || CacheDataManager.uplevelToFra)) {
                    this.lastTime = Date.now() - 450;
                    this.upLevel();
                }
            };
            e.prototype.onDestroy = function () {
                EVUIEffView.offTarget(this);
            };
            e.prototype.updateView = function () {
                if ("" != this.foodId) {
                    var t = CacheDataManager.getMaxStarCount(this.foodId),
                        e = CacheDataManager.getFoodLevel(this.foodId),
                        o = CacheDataManager.getfoodName(this.foodId);
                    this.foodLab.string = o;
                    var a = CacheDataManager.getGetStarCountData(this.foodId, e),
                        i = CacheDataManager.getStarItemCount(this.foodId, a),
                        n = CacheDataManager.getFoodLvToStarIndex(this.foodId, e);
                    if (this.lastId != n) {
                        this.lastId = n;
                        n > 0 && QAudio.play(QAudio.effect_rankup);
                    }
                    this.starLay.setStarView(a, t);
                    var s = CacheDataManager.getFoodCost(this.foodId, e);
                    if ("-1" == s);
                    else {
                        var c = CacheDataManager.getAddAllAddtion(r.AddtionData.zbZk),
                            p = CacheDataManager.mulDot(s, c);
                        s = CacheDataManager.reduceCost(s, p);
                    }
                    var l = !0;
                    this.levelLab.string = "等级:" + e;
                    this.redLab.string = "" + ParseTool.parseAbc(s);
                    var d = n / i;
                    this.proLab.progress = d;
                    this.timeLab.string = CacheDataManager.getFoodBaseCd(this.foodId, e) + "s";
                    this.addLab.string = "" + ParseTool.parseAbc(CacheDataManager.getProfit(this.foodId, e));
                    this.btnRendList.length <= 0 &&
                        (this.btnRendList = this.upLevelBtn.getComponentsInChildren(cc.RenderComponent));
                    var u = !1;
                    if ("-1" == s) {
                        l = !1;
                        u = !0;
                        this.setNodeBool(1);
                        this.zhuanNodeCoin.active = !1;
                    } else {
                        this.setNodeBool(0);
                        this.zhuanNodeCoin.active = !0;
                        CacheDataManager.checkCost(CacheDataManager.getCoinCount(), s) && (l = !1);
                    }
                    this.upLevelBtn.interactable = !u && (!l || u);
                    if (this.btnRendList.length > 0)
                        for (var h = 0; h < this.btnRendList.length; h++)
                            u
                                ? CacheDataManager.setSpriteMat(this.btnRendList[h], !1)
                                : CacheDataManager.setSpriteMat(this.btnRendList[h], !l);
                } else this.lastId = -1;
            };
            e.prototype.setNodeBool = function (t) {
                for (var e = 0; e < this.btnListNode.length; e++) this.btnListNode[e].active = t == e;
            };
            e.prototype.checkNewSend = function () {
                if (1 == GameDataValue.getLastLv() && ("102" == this.foodId || "103" == this.foodId)) {
                    var t = CacheDataManager.getFoodLevel(this.foodId);
                    if (0 == CacheDataManager.getFoodLvToStarIndex(this.foodId, t))
                        switch (this.foodId) {
                            case "102":
                                this.sendFoodId102();
                                break;
                            case "103":
                                this.sendFoodId103();
                        }
                }
            };
            e.prototype.sendFoodId102 = function () {
                var t = CacheDataManager.getFoodLevel(this.foodId);
                switch (CacheDataManager.getGetStarCountData(this.foodId, t)) {
                    case 2:
                        QReport.sendOnce("100126");
                        break;
                    case 3:
                        QReport.sendOnce("100151");
                }
            };
            e.prototype.sendFoodId103 = function () {
                var t = CacheDataManager.getFoodLevel(this.foodId);
                switch (CacheDataManager.getGetStarCountData(this.foodId, t)) {
                    case 1:
                        QReport.sendOnce("100211");
                        break;
                    case 2:
                        QReport.sendOnce("100226");
                        break;
                    case 3:
                        QReport.sendOnce("100251");
                }
            };
            e.prototype.upLevel = function () {
                var t = this,
                    e = CacheDataManager.getCoinCount(),
                    o = CacheDataManager.getFoodLevel(this.foodId),
                    a = CacheDataManager.getFoodCost(this.foodId, o);
                if (CacheDataManager.checkCost("0", a)) {
                    if ("104" == this.foodId && GameDataValue.getLastLv() < 7 && !PayData.isOverKey("FirstPay")) {
                        PayData.setOverKey("FirstPay", !0);
                        this.scheduleOnce(function () {
                            EVUIEffView.emit(EVUIEffView.closeShop);
                        }, 1);
                        console.log("UnLockDlg ----------------- 显示首充");
                    }
                } else {
                    var i = CacheDataManager.getAddAllAddtion(r.AddtionData.zbZk),
                        n = CacheDataManager.mulDot(a, i);
                    a = CacheDataManager.reduceCost(a, n);
                    if (CacheDataManager.checkCost(e, a)) {
                        var s = CacheDataManager.reduceCost(e, a);
                        CacheDataManager.setCoinCount(s);
                        TaskGameEvent.emit(TaskGameEvent.upLevelFood, this.foodId, !1);
                        this.checkNewSend();
                        "101" == this.foodId && QReport.sendOnce(100002 + o + "");
                        "102" == this.foodId && o < 10 && QReport.sendOnce(100101 + o + "");
                        this.scheduleOnce(function () {
                            CacheDataManager.updateCostDataView = !0;
                            var e = CacheDataManager.getFoodLevel(t.foodId);
                            if (
                                0 == CacheDataManager.getFoodLvToStarIndex(t.foodId, e) &&
                                !CacheDataManager.isAddEquiptIP(t.foodId, e)
                            ) {
                                var o = CacheDataManager.getUpLevelRewardCount(t.foodId, e);
                                "" != o &&
                                    EVUIEffView.emit(
                                        EVUIEffView.moveZhuanShi,
                                        t.zhuanNodeCoin.convertToWorldSpaceAR(cc.Vec2.ZERO),
                                        2,
                                        o + "",
                                        "0"
                                    );
                                CacheDataManager.setAddEquipTip(t.foodId, e, !0);
                                EVUIEffView.emit(EVUIEffView.addTipCom, 0);
                            }
                        });
                    } else this.cancelClick();
                }
            };
            n([d(c.default)], e.prototype, "starLay", void 0);
            n([d(cc.Label)], e.prototype, "addLab", void 0);
            n([d(cc.Label)], e.prototype, "foodLab", void 0);
            n([d(cc.Label)], e.prototype, "levelLab", void 0);
            n([d(cc.Label)], e.prototype, "redLab", void 0);
            n([d(cc.Label)], e.prototype, "timeLab", void 0);
            n([d(cc.Button)], e.prototype, "upLevelBtn", void 0);
            n([d(cc.Node)], e.prototype, "upLevelNode", void 0);
            n([d(cc.Node)], e.prototype, "zhuanNodeCoin", void 0);
            n([d([cc.Node])], e.prototype, "btnListNode", void 0);
            n([d(cc.ProgressBar)], e.prototype, "proLab", void 0);
            return n([l], e);
        })(s.default));
o.default = u;
